package gdut.stream.middle;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

public class DistinctTest {
    public static void main(String[] args) {
        List<Student> students = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            Student student = new Student(i, "student" + i);
            students.add(student);
        }
        students.add(new Student(0, "student0"));//添加一个相同的学生
        Stream<Student> studentStream = students.stream();
//        distinct依赖Object的equals方法来判断是否是相同对象，从而去重流中的元素
        studentStream
                .distinct()
                .forEach(student -> System.out.println(student));
    }
}
